import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import java.util.Properties;
/**
 * Created by Administrator on 2017/11/30.
 */
public class MailUtils {
    public static void main(String[] args) throws MessagingException {
        Properties prop = new Properties();
        prop.setProperty("mail.host","smtp.163.com");
        prop.setProperty("mail.smtp.auth","true");
        Authenticator authenticator = new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication("zhwj1991329@163.com","zhao1982415");
            }
        };
        Session session = Session.getDefaultInstance(prop,authenticator);
        Message message = new MimeMessage(session);
        message.setFrom(new InternetAddress("zhaoj1991329@163.com"));
        message.addRecipient(Message.RecipientType.TO,new InternetAddress("zhwj1991329@163.com"));
        message.addRecipient(Message.RecipientType.CC,new InternetAddress("370268540@qq.com"));
        message.setSubject("来自软件1602对邮件");
        message.setContent("我对测试邮件","text/html;charset=UTF-8");
    }
}
